package gaoyijiankao;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.*;

public class Test {

    public static void test(String[] args) {
        Map<String, Object> row1 = new LinkedHashMap<>();
        row1.put("姓名", "张三");
        row1.put("年龄", 23);
        row1.put("成绩", 88.32);
        row1.put("是否合格", true);
        row1.put("考试日期", DateUtil.date());

        Map<String, Object> row2 = new LinkedHashMap<>();
        row2.put("姓名", "李四");
        row2.put("年龄", 33);
        row2.put("成绩", 59.50);
        row2.put("是否合格", false);
        row2.put("考试日期", DateUtil.date());

        ArrayList<Map<String, Object>> rows = CollUtil.newArrayList(row1, row2);

        // 通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("E:/writeMapTest.xlsx");
        // 合并单元格后的标题行，使用默认标题样式
        writer.merge(row1.size() - 1, "一班成绩单");
        // 一次性写出内容，使用默认样式，强制输出标题
        writer.write(rows, true);
        // 关闭writer，释放内存

        writer.setSheet(1);
        writer.write(rows,true);

        writer.close();
    }

    public List<Map<String,Object>> readDatas(){
        ExcelReader reader= ExcelUtil.getReader(FileUtil.file("E:\\考试编排\\四校联考\\四校联考考号编排.xls"), "段考一考号编排");
        List<Map<String,Object>> readAll = reader.readAll();
        return readAll;
    }

    public static void main(String[] args) {
        ArrayList<Map<String,Object>> datas= (ArrayList<Map<String, Object>>) new Test().readDatas();
        int shengwu=0;
        int dili=0;
        int huaxue=0;
        int zhengzhi=0;
        int lishi=0;
        int wuli=0;
        Iterator<Map<String,Object>> iterator=datas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.indexOf("历")!=-1){
                lishi++;
            }
            if(type.indexOf("物")!=-1){
                wuli++;
            }
            if(type.indexOf("生")!=-1){
                shengwu++;
            }
            if(type.indexOf("地")!=-1){
                dili++;
            }
            if(type.indexOf("化")!=-1){
                huaxue++;
            }
            if(type.indexOf("政")!=-1){
                zhengzhi++;
            }
        }
        System.out.println("选科生物："+shengwu+"人、地理："+dili+"人、化学："+huaxue
                +"人、政治："+zhengzhi+"人、历史："+lishi+"人、物理："+wuli+"人");
    }
}
